﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace USB2XXX
{
    class USB2DIO
    {
        //定义函数返回错误代码
        public const Int32 DIO_SUCCESS = (0);   //函数执行成功
        public const Int32 DIO_ERR_NOT_SUPPORT = (-1);  //适配器不支持该函数
        public const Int32 DIO_ERR_USB_WRITE_FAIL = (-2);  //USB写数据失败
        public const Int32 DIO_ERR_USB_READ_FAIL = (-3);  //USB读数据失败
        public const Int32 DIO_ERR_CMD_FAIL = (-4);  //命令执行失败
        public const Int32 DIO_ERR_ARG = (-5);  //传入函数参数异常
        //DIO引脚宏定义
        public const UInt32 DIO_PIN_LIN1	=	0x0001;
        public const UInt32 DIO_PIN_LIN2	=	0x0002;
        public const UInt32 DIO_PIN_LIN3	=	0x0004;
        public const UInt32 DIO_PIN_LIN4	=	0x0008;
        public const UInt32 DIO_PIN_DI0		=	0x0010;
        public const UInt32 DIO_PIN_DI1		=	0x0020;
        public const UInt32 DIO_PIN_DI2		=	0x0040;
        public const UInt32 DIO_PIN_DI3		=	0x0080;
        public const UInt32 DIO_PIN_DO0		=	0x0100;
        public const UInt32 DIO_PIN_DO1		=	0x0200;
        public const UInt32 DIO_PIN_DO2		=	0x0400;
        public const UInt32 DIO_PIN_DO3		=	0x0800;

        /**
         * @brief  初始化DIO,将对应引脚初始化为DIO功能
         * @param  DevHandle 设备号，通过调用 @ref USB_ScanDevice 获取
         * @param[in]  PinMask 需要初始化的DIO引脚，可以参考 @ref DIO引脚宏定义
         * @return 函数执行状态
         * @retval =0 函数执行成功
         * @retval <0 函数调用失败
         */
        [DllImport("USB2XXX.dll")]
        public static extern Int32 DIO_Init(Int32 DevHandle,UInt32 PinMask);

        /**
         * @brief  控制DIO引脚输出高电平
         * @param  DevHandle 设备号，通过调用 @ref USB_ScanDevice 获取
         * @param[in]  PinMask 需要初始化的DIO引脚，可以参考 @ref DIO引脚宏定义
         * @return 函数执行状态
         * @retval =0 函数执行成功
         * @retval <0 函数调用失败
         */
        [DllImport("USB2XXX.dll")]
        public static extern Int32 DIO_SetPins(Int32 DevHandle,UInt32 PinMask);

        /**
         * @brief  控制DIO引脚输出低电平
         * @param  DevHandle 设备号，通过调用 @ref USB_ScanDevice 获取
         * @param[in]  PinMask 需要初始化的DIO引脚，可以参考 @ref DIO引脚宏定义
         * @return 函数执行状态
         * @retval =0 函数执行成功
         * @retval <0 函数调用失败
         */
        [DllImport("USB2XXX.dll")]
        public static extern Int32 DIO_ResetPins(Int32 DevHandle,UInt32 PinMask);

        /**
         * @brief  设置PWM相位参数值
         * @param  DevHandle 设备号，通过调用 @ref USB_ScanDevice 获取
         * @param[in]  PinMask 需要初始化的DIO引脚，可以参考 @ref DIO引脚宏定义
         * @return 函数执行状态
         * @retval >=0 读到的引脚状态
         * @retval <0 函数调用失败
         */
        [DllImport("USB2XXX.dll")]
        public static extern Int32 DIO_ReadPins(Int32 DevHandle,UInt32 PinMask);
    }
}
